import * as axios from 'axios'
import Qs from 'qs'
let options = {}
// The server-side needs a full url to works
if (process.server) {
  options.baseURL = `http://${process.env.HOST || 'localhost'}:${process.env.PORT || 3000}`
}

options.headers={
  'Content-Type': 'application/x-www-form-urlencoded'
}
const instance = axios.create(options);
instance.interceptors.request.use(config => {
  config.data = Qs.stringify(config.data)
  return config
}, error => {
  return Promise.reject(error);
})
export default instance;
